package _04_栈与队列;

import _03_链表.LinkedList;
import _01_第一季._00_公共接口.Deque;

/*
    双向链表实现的双端队列
 */
public class LinkedDeque<E> implements Deque<E> {
    private LinkedList<E> list = new LinkedList<>();
    @Override
    public int size() {
        return list.size();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void enQueueRear(E element) { //队尾入队
        list.add(element);
    }

    @Override
    public E deQueueFront() { //队头出队
        return list.remove(0);
    }

    @Override
    public void enQueueFront(E element) { //队头入队
        list.add(0,element);
    }

    @Override
    public E deQueueRear() { //队尾出队
        return list.remove(list.size()-1);
    }

    @Override
    public E front() {
        return list.get(0);
    }

    @Override
    public E rear() {
        return list.get(list.size()-1);
    }

    @Override
    public void clear() {
        list.clear();
    }
}
